package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.pojo.Community;
import com.qf.pojo.Equipment;
import com.qf.pojo.JSONResult;
import com.qf.service.CommunityService;
import com.qf.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/equipment")
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;


    //查询所有资产设备
    @RequestMapping("/equipmentList")
    public JSONResult equipmentList (@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize
                                     ) {
        //设置分页条件
        PageHelper.startPage(pageNum, pageSize);

        //查新所有
        List<Equipment> equipments = equipmentService.findAllEquipment();
        System.out.println("-----------------------");
        System.out.println(equipments);
        //分页对象
        PageInfo<Equipment> pageInfo = new PageInfo<>(equipments);

        JSONResult jsonResult = new JSONResult();
        //自定义状态码
        jsonResult.setCode(0);
        //总记录数
        jsonResult.setCount(pageInfo.getTotal());
        //传回前端信息
        jsonResult.setMsg("success");
        //数据
        jsonResult.setData(equipments);

        System.out.println("-----------------------");
        System.out.println(equipments);
        System.out.println(jsonResult);
        return jsonResult;
    }

}
